package main

import (
	"log"

	"gitee.com/baidugoogle/rtsp-server/server"
	"github.com/general252/gout/ushutdown"
)

func init() {
	log.SetFlags(log.Lshortfile | log.LstdFlags)
}

func main() {
	// rtsp server (rtsp)
	// rtp、rtcp端口
	// 通用的根据端口判断流的session
	//
	// server
	//   session
	//      push session
	//      pull session
	//          sdp
	//          rtp、rtcp 包
	//
	// 服务器缓存rtp包
	// 服务器处理rtcp包, 由服务器处理丢包重传、I帧请求
	//

	cfg := server.RtspConfig{
		RtspPort: 554,
		RtpPort:  8000,
		RtcpPort: 8001,
	}

	s, err := server.NewServer(cfg)
	if err != nil {
		log.Println(err)
		return
	}

	s.AddHandle("abc", &server.UnimplementedEventHandler{
		SessionOpen: func(session *server.RtspSession) {
			log.Println("session SessionOpen")
		},
		SessionClose: func(session *server.RtspSession) {
			log.Println("session SessionClose")
		},
		Announce: func(session *server.RtspSession) {
			log.Println("session Announce")
		},
		Record: func(session *server.RtspSession) {
			log.Println("session Record")
		},
		Setup: func(session *server.RtspSession) {
			log.Println("session Setup")
		},
		Describe: func(session *server.RtspSession) {
			log.Println("session Describe")
		},
		Play: func(session *server.RtspSession) {
			log.Println("session Play")
		},
	})

	log.Printf("listen on %v", cfg.RtspPort)
	ushutdown.NewHook().WithStopHandler(func() {
		log.Println("rtsp server stop")
	}).GracefulStop()
}
